package com.leng.util;

/**
 * 货币工具类 日期：2017/3/11
 * 
 * @author wangyiyin
 *
 */
public class CurrencyUtils {

	/**
	 * 整型元转成分
	 * 
	 * @param yuan
	 * @return
	 */
	public String yuanToFen(Integer yuan) {
		// TODO 整型元转成分
		return null;
	}

	/**
	 * 整型分转成元
	 * 
	 * @param fen
	 * @return
	 */
	public static String fenToYuan(Integer fen) {
		if (null != fen) {
			if (0 == fen) {
				return "0";
			}
			return String.valueOf(fen / 100.0);
		}
		return null;
	}

	/**
	 * 整型分转成元,如果是正数，则把“+”符号也显示出来,5则显示+5
	 * 
	 * @param fen
	 * @return
	 */
	public static String fenToYuanWithSymbol(Integer fen) {
		if (null != fen) {
			if (0 == fen) {
				return "-";
			}
			String str = String.valueOf(+fen / 100.0);
			if(fen >0){
				str = "+"+str;
			}
			return str;
		}
		return null;
	}

	/**
	 * 将元为单位的转换为分 替换小数点，支持以逗号区分的金额
	 * 
	 * @param amount
	 * @return
	 */
	public static String yuanToFen(String amount) {
		int index = amount.indexOf(".");
		int length = amount.length();
		Long amLong = 0l;
		if (index == -1) {
			amLong = Long.valueOf(amount + "00");
		} else if (length - index >= 3) {
			amLong = Long.valueOf((amount.substring(0, index + 3)).replace(".", ""));
		} else if (length - index == 2) {
			amLong = Long.valueOf((amount.substring(0, index + 2)).replace(".", "") + 0);
		} else {
			amLong = Long.valueOf((amount.substring(0, index + 1)).replace(".", "") + "00");
		}
		return amLong.toString();
	}

	public static void main(String[] args) {
		System.out.println(fenToYuanWithSymbol(55));
	}
}
